<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.org/ui"
	template="/templates/masterLayout.xhtml">

	<ui:define name="pageTitle">#{out.partners_title}</ui:define>
	<ui:define name="header"> -> #{out.importers_title}</ui:define>

	<ui:define name="head-extra">
	</ui:define>

	<ui:define name="content">
		<h:form id="needList">
			<p:dataTable var="need" id="needTable"
				rendered="#{importerNecessaryProducts.importList.size()>0}"
				value="#{importerNecessaryProducts.importList}">
				<p:column headerText="Product">
					<h:outputText value="#{need.product.name}" />
				</p:column>
				<p:column headerText="Need Quantity">
					<p:inputText id="quantity" value="#{need.need}">
						<p:ajax event="keyup" />
					</p:inputText>
				</p:column>
				<p:column headerText="Ready Quantity" style="display:none;">
				</p:column>
				<p:column headerText="Ready Date" style="display:none;">
				</p:column>
				<p:column headerText="Sign" style="display:none;">
				</p:column>
				<p:column headerText="Remove" exportable="false">
					<p:commandButton value="Remove"
						action="#{importerNecessaryProducts.removeFromImportList(need)}"
						update=":needList" />
				</p:column>
			</p:dataTable>
			<h:commandLink id="csv">
				<p:graphicImage name="/images/csv.png"
					style="width:40px;height:40px;" />
				<p:dataExporter type="csv" target="needTable"
					fileName="Needed products" />
			</h:commandLink>
			<h:commandLink id="pdf">
				<p:graphicImage name="/images/pdf.png"
					style="width:40px;height:40px;" />
				<p:dataExporter type="pdf" target="needTable"
					fileName="Needed products" />
			</h:commandLink>
			<h:commandLink id="xml">
				<p:graphicImage name="/images/xml.png"
					style="width:40px;height:40px;" />
				<p:dataExporter type="xml" target="needTable"
					fileName="Needed products" />
			</h:commandLink>
			<h:commandLink id="xls">
				<p:graphicImage name="/images/xls.png"
					style="width:40px;height:40px;" />
				<p:dataExporter type="xls" target="needTable"
					fileName="Needed products" />
			</h:commandLink>
		</h:form>
		<br />
		<p:dataTable var="need"
			value="#{importerNecessaryProducts.needListOfProducts}">
			<p:column headerText="Product">
				<h:outputText value="#{need.product.name}" />
			</p:column>
			<p:column headerText="Need Quantity">
				<h:outputText value="#{need.need}"
					style="font-weight:bold;color:red;" />
				<h:outputText value=" / #{need.originalQuantity}" />
			</p:column>
			<p:column headerText="In WH Quantity">
				<h:outputText value="#{need.inWHQuantity}" />
			</p:column>
			<p:column headerText="Add to import list">
				<h:form>
					<p:commandButton value="ADD"
						action="#{importerNecessaryProducts.addToImportList(need)}"
						update=":needList" />
				</h:form>
			</p:column>
		</p:dataTable>
		<h:form id="newNeed">
			<p:panelGrid columns="3">
				<p:column>
					<h:outputText value="Search Product" />
					<p:autoComplete id="product"
						value="#{importerNecessaryProducts.newNeed.product}"
						completeMethod="#{importerNecessaryProducts.completeText}" var="c"
						itemLabel='#{c.name}'
						itemValue="#{c}"
						converter="productConverterOfImporterNecessaryProducts" />
				</p:column>
				<p:column>
					<h:outputText value="Quantity" />
					<p:inputText id="quantity"
						value="#{importerNecessaryProducts.newNeed.need}">
						<p:ajax event="keyup" />
					</p:inputText>
				</p:column>
				<p:column>
					<h:form>
						<p:commandButton value="ADD"
							action="#{importerNecessaryProducts.addToImportList(importerNecessaryProducts.newNeed)}"
							update=":needList" />
					</h:form>
				</p:column>
			</p:panelGrid>
		</h:form>
	</ui:define>

</ui:composition>